using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using DAL;
using BUS;
using Utility;
public partial class Admin_Chitietdonhang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
//        if (Request.Url.ToString().Contains("dangnhap.aspx") == false
//&& Session["UserName"] == null)
//            Response.Redirect("~/Admin/dangnhap.aspx");
//        if (!IsPostBack)
//        {
            LoadData();
//        }
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbDonhang dh = tbDonhangBUS.GetByID(id);
            lit_mahd.Text = dh.Madh.ToString();

            tbKhachhang kh = tbKhachhangBUS.GetByID(dh.Makh);
            lit_kh.Text = kh.Tenkh;
            lit_ngaydh.Text = dh.Ngaydathang.ToString();
            lit_ngayg.Text = dh.Ngaygiaohang.ToString();
            lit_tongt.Text = dh.Trigia.ToString();
            tbTrangthaidonhang tt = tbTrangthaidonhangBUS.GetByID(dh.Matt);
            lit_dagiao.Text = tt.Trangthai;

            Criteria c = new Criteria();
            c.add(Condition.AND, tbDonhangColumn.Madh, Condition.EQUAL, id);
            int total = 0;
            tbChitietdhCollection ctCollection =
             tbChitietdhBUS.Get(c.Criter, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize,
                tbChitietdhColumn.Madh.ToString(), OrderDirection.ASC.ToString(), out total);
            Repeater1.DataSource = ctCollection;
            Repeater1.DataBind();
            hyperlinkPager.ItemCount = total;
        }
        catch
        {
            Response.Redirect("~/Admin/Danhsachdonhang.aspx");
        }
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
        e.Item.ItemType == ListItemType.Item)
        {
            tbChitietdh ctdh = (tbChitietdh)e.Item.DataItem;
            tbSanpham sp = tbSanphamBUS.GetByID(ctdh.Masp);
            if (sp != null)
            {
                Literal lit_tensp = (Literal)e.Item.FindControl("lit_tensp");
                lit_tensp.Text =sp.Tensp;
            }
            Literal lit_thanhtien = (Literal)e.Item.FindControl("lit_thanhtien");
            double tongTien = ctdh.Soluong * ctdh.Dongia;
            lit_thanhtien.Text = tongTien.ToString();
        }
    }
    //protected void hyperlinkPager_Command(object sender, CommandEventArgs e)
    //{
    //    hyperlinkPager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
    //    LoadData();
    //}
}

